package com.hengpeng.itfinoss.controller.fund;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hengpeng.common.web.tags.ListTag.Pagination;
import com.hengpeng.itfinbase.persist.Transfer;
import com.hengpeng.itfinoss.controller.BaseController;
import com.hengpeng.itfinoss.service.ServiceFactory;

@Controller
@RequestMapping("/transfer")
public class TransferController extends BaseController
{
	@Autowired
	private ServiceFactory serviceFactory;

	@RequestMapping(value = "/list")
	public String list(ModelMap map, HttpServletRequest request, String outTrustAccountId, String inTrustAccountId)
	{
		Pagination page = new Pagination(request);
		page.setPageSize(this.getPageSize(request));
		List<Transfer> list = new ArrayList<Transfer>();
		map.put("outTrustAccountId", outTrustAccountId);
		map.put("inTrustAccountId", inTrustAccountId);
		List<Transfer> result = serviceFactory.getTransferService()
				.findWithPage(outTrustAccountId, inTrustAccountId, page.currentPage, page.pageSize, null)
				.getReturnValue();
		Long count = serviceFactory.getTransferService().queryCount(outTrustAccountId, inTrustAccountId)
				.getReturnValue();
		page.setEntityCount(count.intValue());
		list.addAll(result);
		map.put("list", list);
		map.put("page", page);
		return "fund/transfer/list";
	}

	@RequestMapping(value = "/detail/{id}")
	public String detail(ModelMap map, HttpServletRequest request, @PathVariable Long id)
	{
		Transfer transfer = serviceFactory.getPersistService().get(Transfer.class, id);

		map.put("transfer", transfer);
		return "fund/transfer/detail";
	}

}
